package com.cdwh.joylife.net;

import android.content.Context;


import com.cdwh.joylife.bean.response.BaseResponse;
import com.cdwh.joylife.presenter.ViewInterface;
import com.socks.library.KLog;

/**
 * Created by walln on 2016/12/14.
 */

public class MyFilter implements FilterInterface {

    private Context context;
    private ViewInterface viewInterface;
    private boolean isDispatch = true;

    public MyFilter(Context context, ViewInterface viewInterface) {
        this.context = context;
        this.viewInterface = viewInterface;
    }

    public void setDispatch(boolean dispatch) {
        isDispatch = dispatch;
    }

    @Override
    public void onSuccess(Object data) {
        this.onSuccess(data, 0);
    }

    @Override
    public void onSuccess(Object data, int type) {
        BaseResponse response = (BaseResponse) data;
//        if (response.getCode() == ResultEnum.SUCCESS) {
//
//            if (type == 0) {
//                viewInterface.onReceive(data);
//            } else {
//                viewInterface.onReceive(data, type);
//            }
//        }
    }

    private boolean isFirstError = true;


    @Override
    public void onError(Object msg, int type) {

        KLog.e("错误。。。。。。。");
        Throwable throwable = (Throwable) msg;
        KLog.e(throwable.toString());

        viewInterface.onError(throwable, type);
        isFirstError = false;
    }
}
